import { getCurrentInstance } from 'vue';
import api from '@/api';
export const useFlowImg = () => {
    const instance: any = getCurrentInstance();
    const showFlowImg = (src) => {
        instance.proxy.$mitt.emit('previewImg', src);
    };
    const getFlowImg = async (instanceId: string) => {
        const query = {
            instanceId
        };
        const res = await api.historyModel.getProcessPic(query, {
            responseType: 'blob'
        });
        return new Promise((resolve, reject) => {
            if (res) {
                const blob = new Blob([res], { type: 'image/jpeg' });
                const reader = new FileReader();
                reader.readAsDataURL(blob);
                reader.onload = (e: any) => {
                    resolve(e.target.result);
                };
                reader.onerror = (e: any) => {
                    reject(e.target.result);
                };
            }
        });
    };
    return {
        showFlowImg,
        getFlowImg
    };
};